<?xml version="1.0" encoding="UTF-8" ?>



<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
	xmlns:tmt="http://www.massimocorner.com/validator">
	<xsl:param name="DOTNET2"/>
	
	<xsl:output method="html" indent="yes"/>
	
	
	

	<xsl:template match="Instance">

using System;
using System.Collections.Generic;
using System.Text;

using System.Xml.Serialization;

using AjaxPro;

namespace <xsl:value-of select="HeaderInfo/ProjectName"/>Library.Instance
{

	[AjaxPro.AjaxNamespace("<xsl:value-of select="Name"/>AJAX")]
	[Serializable]
	public class <xsl:value-of select="Name"/> : <xsl:value-of select="HeaderInfo/ProjectName"/>.Instance.<xsl:value-of select="Name"/>
	{

		[AjaxMethod]
		public override <xsl:value-of select="HeaderInfo/ProjectName"/>.Instance.<xsl:value-of select="Name"/> GetInstance ()
		{
			return ( <xsl:value-of select="HeaderInfo/ProjectName"/>.Instance.<xsl:value-of select="Name"/> ) new <xsl:value-of select="Name"/> ();
		}


		[AjaxMethod]
		public override bool HandleIncoming ( <xsl:value-of select="HeaderInfo/ProjectName"/>.Instance.<xsl:value-of select="Name"/> @object , string method )
		{
			// This requires implementation, remember however that
			// the 'save' method provides lovely functionality
			// for doing this within session state.
			return true;
		}
		
		// Use the names set here to load value
		[AjaxMethod]
		public override <xsl:value-of select="HeaderInfo/ProjectName"/>.Instance.<xsl:value-of select="Name"/> GetLoaded ( string name , string value ) 
		
		{
			if ( name == null &amp;&amp; value == null )
			{
				return GetInstance();
			}
			
			// Implement from here on in
			
			return GetInstance();
		}
		
		
		[AjaxMethod( HttpSessionStateRequirement.ReadWrite )]
		public override bool Save ( bool unique , 
			<xsl:value-of select="HeaderInfo/ProjectName"/>.Instance.<xsl:value-of select="HeaderInfo/ProjectName"/>InstanceObject obj )
		{
			obj.dirty = true;
			// The KnownClasses have information in the typeof
			<xsl:for-each select="ClassAttribs/ClassAttributes">
				<xsl:if test="KnownClass='true'">
					<xsl:value-of select="Name"/> = new <xsl:value-of select="//HeaderInfo/ProjectName"/>.DataObject.<xsl:value-of select="Type"/> ( <xsl:value-of select="PropertyName"/>Guid );
				</xsl:if>
			</xsl:for-each>
			return Save ( unique , this.GetType() , obj );
		}
		
		[AjaxMethod( HttpSessionStateRequirement.ReadWrite )]
		public override  <xsl:value-of select="HeaderInfo/ProjectName"/>.Instance.<xsl:value-of select="HeaderInfo/ProjectName"/>InstanceObject Load ( bool unique , Guid id )
		{
			this.InstanceID = id;
			return Load ( unique , this.GetType() );
		}
		
		[AjaxMethod( HttpSessionStateRequirement.ReadWrite )]
		public override bool Delete ( bool unique , Guid id )
		{
			this.InstanceID = id;
			return Delete ( unique , this.GetType() );
		}
		
		
		
		<xsl:apply-templates select="ClassAttribs"/>
		

	
	
    }
}

	
	</xsl:template>
	
	
	
	<xsl:template match="ClassAttributes">
		
		
		<xsl:if test="IsEnum='true'">
		
		[XmlIgnore]
		public override string[] <xsl:value-of select="PropertyName"/>_VALS {
			get 
			{ 
				return Enum.GetNames(typeof(<xsl:value-of select="//HeaderInfo/ProjectName"/>.DataObject.<xsl:value-of select="Type"/>)); 
			}
		}
		
		</xsl:if>
		
		
		
		
		<xsl:if test="KnownClass='true'">
		
		[XmlIgnore]
		public override <xsl:value-of select="//HeaderInfo/ProjectName"/>.DataObject.<xsl:value-of select="Type"/>.<xsl:value-of select="Type"/>Small[] <xsl:value-of select="PropertyName"/>_VALS
		{
			get 
			{
				return <xsl:value-of select="//HeaderInfo/ProjectName"/>.DataObject.<xsl:value-of select="Type"/>.GetSmall();
			}
		}
		
		</xsl:if>
		
		



	</xsl:template>
	
</xsl:stylesheet>